package tests;

import example.plugins.automaton.Constants;
import example.plugins.automaton.ConwayState;
import example.plugins.automaton.SquareGrid;
import framework.grid.Location;

/**
 * Class supports all the optional tests for the framework
 * @author Bill Ge, May Zhai, Alex Yoo
 *
 */
public class ApplicationTests {
	/**
	 * method houses all the optional tests
	 * <br> Each test will print that it was successful if it passes.
	 * <br> Otherwise a failure statement will be printed
	 */
	public static void optionalTests(){
		printTest();
		locationEquivalent();
		printLocation();
	}
	/**
	 * Tests the toString method of SquareGrid
	 */
	public static void printTest(){
		SquareGrid squareGrid = new SquareGrid(10);
		ConwayState live = new ConwayState(Constants.ALIVE);
		ConwayState dead = new ConwayState(Constants.DEAD);
		
		for(int i = 0; i<squareGrid.getNumCols(); i++){
			for(int j = 0; j<squareGrid.getNumRows(); j++){
				squareGrid.put(new Location(i,j), dead);
			}
		}
		squareGrid.put(new Location(0,0), live);
		
		String grid = squareGrid.toString();
		int index = grid.indexOf("1");
		if(index ==0){
			System.out.println("printTest passed");
			return;
		}
		System.out.println("printTest failed");
	}
	/**
	 * tests the equals method of the Location class
	 */
	public static void locationEquivalent(){
		Location temp = new Location(0,0);
		Location temp1 = new Location(1,0);
		Location temp2 = new Location(0,0);
		if(temp.equals(temp2) && !temp.equals(temp1)){
			System.out.println("locationEquivalent passed");
		}else{
			System.out.println("locationEquivalent failed");			
		}
	}
	/**
	 * tests the toString method of the Location class
	 */
	public static void printLocation(){
		Location temp = new Location(0,0);
		if(temp.toString().equals("(0, 0)")){
			System.out.println("printLocation passed");			
		}else{
			System.out.println("printLocation failed");
		}
		
	}
}
